package com.neu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.RoommanageMapper;
import com.neu.po.Roommanage;
import com.neu.po.RoommanageExample;
import com.neu.po.RoommanageExample.Criteria;
@Service
public class RoommanageServiceImpl implements RoommanageService{
	@Autowired
	private RoommanageMapper roommanageMapper;
	
	
	@Override
	public int insert(Roommanage roommanage) {
		
		return roommanageMapper.insert(roommanage);
	}

	@Override
	public int update(Roommanage roommanage) {
		
		return roommanageMapper.updateByPrimaryKey(roommanage);
		
	}

	@Override
	public int delete(int id) {
		
		return roommanageMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Roommanage> getAllRoom() {
		RoommanageExample example = new RoommanageExample();
		
		return roommanageMapper.selectByExample(example);
	}

	@Override
	public PageInfo<Roommanage> getPagedRoom(int pageNum, int pageSize, String keyword) {
		RoommanageExample example = new RoommanageExample();
		Criteria c = example.createCriteria();
		
		c.andDelmarkEqualTo(1).andRoletypeLike("%"+keyword+"%");
			
		PageHelper.startPage(pageNum, pageSize);
		
		List<Roommanage> list = roommanageMapper.selectByExample(example);
		
		PageInfo<Roommanage> pageInfo = new PageInfo<>(list);
		
		return pageInfo;
	}

	@Override
	public int batchDeleteRoom(List<Integer> ids) {
		RoommanageExample example = new RoommanageExample();
		example.or().andIdIn(ids);		
		
		return roommanageMapper.deleteByExample(example);
	}

	

}
